﻿using GalaSoft.MvvmLight;
using MVVM_CAD.Model;

namespace MVVM_CAD.ViewModel
{
    public class FigurePropertiesViewModel : ViewModelBase
    {
        public const string SelectedFigurePropertyName = "SelectedFigure";
        private IFigure _selectedFigure = null;
        public IFigure SelectedFigure
        {
            get
            {
                return _selectedFigure;
            }

            set
            {
                if (_selectedFigure == value)
                {
                    return;
                }

                var oldValue = _selectedFigure;
                _selectedFigure = value;

                // Update bindings and broadcast change using GalaSoft.MvvmLight.Messenging
                RaisePropertyChanged(SelectedFigurePropertyName, oldValue, value, true);
            }
        }

        public FigurePropertiesViewModel()
        {
            if (IsInDesignMode)
            {
                _selectedFigure = new Line {Name = "Custom Line"};
                _selectedFigure.PointsCollection.Add(new CustomPoint(8, 8));
            }
            else
            {
                // Code runs "for real": Connect to service, etc...
            }
        }
    }
}